package com.example.shopp_2301.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Menu
import com.example.shopp_2301.R
import com.example.shopp_2301.utils.GlideUtils

/**
 * 单布局适配器---菜单
 */
class MenuAdapter:BaseQuickAdapter<Menu,BaseViewHolder>(R.layout.item_menu) {
    override fun convert(holder: BaseViewHolder, item: Menu) {
        //val imageView = holder.getView<ImageView>(R.id.menu_iv)//查找控件
        GlideUtils.loadCircleImage(context,item.pic,holder.getView(R.id.menu_iv))
        holder.setText(R.id.menu_tv,item.name)
    }
}

/**
 * 多布局适配器---菜单
 */
class MenuMutAdapter :BaseMultiItemQuickAdapter<Menu,BaseViewHolder>(){
    init {
        addItemType(0,R.layout.item_menu)
        addItemType(1,R.layout.item_menu)
    }
    override fun convert(holder: BaseViewHolder, item: Menu) {
        if(holder.itemViewType==0){
            GlideUtils.loadCircleImage(context,item.pic,holder.getView(R.id.menu_iv))
            holder.setText(R.id.menu_tv,item.name)
        }else{
            GlideUtils.loadImage(context,item.url,holder.getView(R.id.menu_iv))
            holder.setText(R.id.menu_tv,item.name)
        }
    }

}